#!/bin/python
# -*- coding: utf-8 -*-
"""
Name: path_util.py
Author: harrybao
Mail: harrybao@123u.com
Time: 2021/07/12 16:00
Desc: 路径工具
"""

import os
import shutil

class PathUtil:
    """路径工具类"""
    def __init__(self):
        self._sdk_root_path = os.path.abspath(os.path.dirname(__file__))
        self._sdk_thirdparty_path = os.path.join(self._sdk_root_path, 'thirdparty')
        self._sdk_winproj_path = os.path.join(self._sdk_root_path, 'win-proj')
        self._sdk_src_path = os.path.join(self._sdk_root_path, 'src')
        self._sdk_demo_path = os.path.join(self._sdk_root_path, 'demo')
        self._sdk_package_path = os.path.join(self._sdk_root_path, 'package')
        self._sdk_package_doc_path = os.path.join(self._sdk_package_path, 'doc')
        self._sdk_package_include_path = os.path.join(self._sdk_package_path, 'include')
        self._sdk_package_lib_path = os.path.join(self._sdk_package_path, 'lib')
        self._sdk_package_protobuf_path = os.path.join(self._sdk_package_path, 'protobuf')
        self._sdk_package_proxy_path = os.path.join(self._sdk_package_path, 'proxy')
        self._sdk_package_stub_path = os.path.join(self._sdk_package_path, 'stub')
        self._sdk_package_info_path = os.path.join(self._sdk_package_path, 'info')
    
    @property
    def sdk_root_path(self):
        return self._sdk_root_path
    
    @property
    def sdk_package_path(self):
        return self._sdk_package_path
    
    @property
    def sdk_winproj_path(self):
        return self._sdk_winproj_path
    
    @property
    def sdk_src_path(self):
        return self._sdk_src_path
    
    @property
    def sdk_demo_path(self):
        return self._sdk_demo_path
 
    @property
    def sdk_package_doc_path(self):
        return self._sdk_package_doc_path

    @property
    def sdk_package_include_path(self):
        return self._sdk_package_include_path

    @property
    def sdk_package_lib_path(self):
        return self._sdk_package_lib_path

    @property
    def sdk_package_protobuf_path(self):
        return self._sdk_package_protobuf_path

    @property
    def sdk_package_proxy_path(self):
        return self._sdk_package_proxy_path

    @property
    def sdk_package_stub_path(self):
        return self._sdk_package_stub_path

    @property
    def sdk_package_info_path(self):
        return self._sdk_package_info_path
    
    @property
    def sdk_thirdparty_path(self):
        return self._sdk_thirdparty_path
 
    def check_path(self, path, print_error=True):
        """检查路径"""
        if not os.path.exists(path):
            if print_error:
                print('path not exists: {0}'.format(path))
            return False
        else:
            return True
  
    def go_to_sdk_root_path(self):
        if os.getcwd() != self.sdk_root_path:
            os.chdir(self._sdk_root_path)

    def remove_path(self, path, print_error=True):
        """删除目录"""
        if not os.path.exists(path):
            if print_error:
                print('path not exist: {0}'.format(path))
            return False

        shutil.rmtree(path)
        return True

